﻿using System;
using System.Collections.Generic;

namespace AcademicPlanner.Domain.Models
{
	/// <summary>
	/// InvalidModelPropertiesErrorCollection represents a collection of
	/// validation errors of possible values of <c>Model</c>s' properties.
	/// </summary>
	/// <version>1.0</version>
	/// <since>1.0</since>
	public class InvalidModelPropertiesErrorCollection
	{
		private IDictionary<string, InvalidModelPropertyErrorCode> outerErrors;
		private IDictionary<string, InvalidModelPropertiesErrorCollection> innerErrors;
		private string modelName;


		/// <summary>
		/// Gets the validation errors associated with direct properties of the concerned
		/// <c>Model</c> i.e. not validation errors of one of its aggregate <c>Model</c>s.
		/// </summary>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public IDictionary<string, InvalidModelPropertyErrorCode> OuterErrors { get { return outerErrors; } }

		/// <summary>
		/// Gets the validation errors associated with one of the concerned <c>Model</c>'s
		/// aggregate <c>Model</c>s' direct properties.
		/// </summary>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public IDictionary<string, InvalidModelPropertiesErrorCollection> InnerErrors { get { return innerErrors; } }

		/// <summary>
		/// Gets the name (class name) concerned with the validation errors.
		/// </summary>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public string ModelName { get { return modelName; } }


		/// <summary>
		/// Constructs a InvalidModelPropertiesErrorCollection for a given <c>Model</c>.
		/// </summary>
		/// <param name="pModelName">The name (class name) of the <c>Model</c>.</param>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public InvalidModelPropertiesErrorCollection(string pModelName)
		{
			modelName = pModelName;
			outerErrors = new Dictionary<string, InvalidModelPropertyErrorCode>();
			innerErrors = new Dictionary<string, InvalidModelPropertiesErrorCollection>();
		}


		/// <summary>
		/// Adds a validation error to this InvalidModelPropertiesErrorCollection for a
		/// direct property of the concerned <c>Model</c> i.e. not one of its aggregate <c>Model</c>s
		/// property.
		/// </summary>
		/// <param name="pProperty">The name of the property whose possible value is invalid.</param>
		/// <param name="pCode">The validation error code.</param>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public void AddOuter(string pProperty, InvalidModelPropertyErrorCode pCode)
		{
			outerErrors.Add(pProperty, pCode);
		}

		/// <summary>
		/// Adds a collection of validation error to this InvalidModelPropertiesErrorCollection for an
		/// indirect property of the concerned <c>Model</c> i.e. a property that is an aggregate <c>Model</c>.
		/// </summary>
		/// <param name="pProperty">The name of the property that is an aggregate <c>Model</c>.</param>
		/// <param name="pInnerError">The collection of validation errors for the property's properties.</param>
		/// <version>1.0</version>
		/// <since>1.0</since>
		public void AddInner(string pProperty, InvalidModelPropertiesErrorCollection pInnerError)
		{
			innerErrors.Add(pProperty, pInnerError);
		}
	}
}
